@extends('admin.layouts.app')
@section('title','后台管理欢迎页面')
@section('headerCss')
    @parent
    <link href="{{ asset('admin/assets/css/codemirror.css') }}" rel="stylesheet">
    <link rel="stylesheet" href="{{ asset('admin/assets/css/ace.min.css') }}" />
    <link rel="stylesheet" href="{{ asset('admin/assets/css/font-awesome.min.css') }}" />
@stop
@section('headerJs')
    @parent
    <script src="{{ asset('admin/assets/js/bootstrap.min.js') }}"></script>
    <script src="{{ asset('admin/assets/js/typeahead-bs2.min.js') }}"></script>
@stop
@section('content')
    <div class="margin clearfix">
        <div class="Configure_style">
            <div class="manner">
                <div class="title_name">系统全局配置</div>

                <div class="info clearfix">
                    {!! Form::open(['route' => 'system.store', 'method' => 'post','id'=>'form']) !!}
                    <table class="table table-bordered">
                        <thead>
                        <tr><th width="190px">全局名称</th>
                            <th width="150px">状态</th>
                            <th width="200px">描述</th>
                        </tr></thead>
                        <tbody>
                        <tr>
                            <td>恶劣天气加价</td>
                            <td>
                                @if ($system->is_weather)
                                    <label><input name="weather" value="1" type="radio" class="ace" checked="checked" onclick="EnableWeather(this,'123')"><span class="lbl">启用</span></label>
                                    <label><input name="weather" value="0" type="radio" class="ace" onclick="closeWeather(this,'213')"><span class="lbl">关闭</span></label>
                                    @else
                                    <label><input name="weather" value="1" type="radio" class="ace" onclick="EnableWeather(this,'123')"><span class="lbl">启用</span></label>
                                    <label><input name="weather" value="0" type="radio" class="ace" checked="checked"  onclick="closeWeather(this,'213')"><span class="lbl">关闭</span></label>
                                @endif

                            </td>
                            <td>
                                    @if ($system->is_weather)
                                    <div id="is_weather" style="display: block">
                                        <select class="form-control" id="form-field-select-1" name="weather_type">
                                            <option value="">选择天气类型</option>
                                            @foreach ($weathers as $weather)
                                                @if ($system->weather_type == $weather->id)
                                                    <option selected value="{{ $weather->id }}">{{ $weather->name }}</option>
                                                    @else
                                                    <option value="{{ $weather->id }}">{{ $weather->name }}</option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </div>
                                        @else
                                    <div id="is_weather" style="display: none">
                                        <select class="form-control" id="form-field-select-1" name="weather_type">
                                            <option value="">选择天气类型</option>
                                            @foreach ($weathers as $weather)
                                                <option value="{{ $weather->id }}">{{ $weather->name }}</option>
                                            @endforeach

                                        </select>
                                    </div>
                                    @endif

                            </td>
                        </tr>
                        <tr>
                            <td>是否开启赠送优惠券</td>
                            <td>
                                @if ($system->is_coupon)
                                    <label><input name="coupon" type="radio" class="ace" value="1" checked="checked" onclick="EnableCoupon(this,'124')"><span class="lbl">启用</span></label>
                                    <label><input name="coupon" type="radio" class="ace" value="0" onclick="closeCoupon(this,'214')"><span class="lbl">关闭</span></label>
                                    @else
                                    <label><input name="coupon" type="radio" class="ace" value="1"  onclick="EnableCoupon(this,'124')"><span class="lbl">启用</span></label>
                                    <label><input name="coupon" type="radio" class="ace" value="0" checked="checked" onclick="closeCoupon(this,'214')"><span class="lbl">关闭</span></label>
                                @endif

                            </td>
                            <td>
                                @if ($system->is_coupon)
                                    <div id="is_coupon" style="display: block">
                                        <select class="form-control" id="form-field-select-1" name="coupon_type">
                                            <option value="">选择券类型</option>
                                            @foreach ($coupons as $coupon)
                                                @if ($system->coupon_type == $coupon->id)
                                                    <option selected value="{{ $coupon->id }}">{{ $coupon->name }}</option>
                                                    @else
                                                    <option value="{{ $coupon->id }}">{{ $coupon->name }}</option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </div>
                                    @else
                                    <div id="is_coupon" style="display: none">
                                        <select class="form-control" id="form-field-select-1" name="coupon_type">
                                            <option value="">选择券类型</option>
                                            @foreach ($coupons as $coupon)
                                                <option value="{{ $coupon->id }}">{{ $coupon->name }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                @endif

                            </td>

                        </tr>
                        <tr>
                            <td>就近购买价格(0-2公里)</td>
                            <td>
                                @if ($system->fixed_price)
                                    <input name="fixed_price" type="text" value="{{ $system->fixed_price }}" class="text_add" placeholder="" style=" width:80px">
                                @endif
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>最大公里数({{ ceil($system->max_kil) }})</td>
                            <td>
                                @if ($system->max_kil)
                                    <input name="max_kil" type="text" value="{{ $system->max_kil }}" class="text_add" placeholder="" style=" width:80px">
                                @endif
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>超出最大{{$system->max_kil}}公里（每公里收）</td>
                            <td>
                                @if ($system->exceed_price)
                                    <input name="exceed_price" type="text" value="{{ $system->exceed_price }}" class="text_add" placeholder="" style=" width:80px">
                                @endif
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <div class="Button_operation">
                                    <button type="" class="btn btn-primary radius">保存并提交</button>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    {!! Form::close() !!}
                </div>
            </div><!--其他配置-->
        </div>

    </div>
@stop
@section('js')
    <script>
        function EnableWeather(){ $('#is_weather').css('display','block');}
        function closeWeather(){$('#is_weather').css('display','none')}

        function EnableCoupon(){ $('#is_coupon').css('display','block');}
        function closeCoupon(){$('#is_coupon').css('display','none')}
    </script>

    <script type="text/javascript">
        $('#form').Validform({
            tiptype : 4,
            ajaxPost : true,
            beforeCheck:function(curform){
                console.log(curform);
                //在表单提交执行验证之前执行的函数，curform参数是当前表单对象。
                //这里明确return false的话将不会继续执行验证操作;
                index = layer.load(1, {shade: [0.6, '#393D49']});
            },
            callback : function (res) {
                console.log(res);
                if(res.status == 422) {
                    var json=JSON.parse(res.responseText);
                    $.each(json.errors, function(idx, obj) {
                        layer.msg(obj[0], {icon: 5});
                        layer.close(index);
                        return false;
                    });
                } else if(res.status== 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.close(index);
                        location.href = '{{ route('system.index') }}'
                    });

                }
            },
        });
    </script>
@stop
